package colin.spring.boot.sample.web.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import colin.spring.boot.sample.web.dao.LoggerDao;
import colin.spring.boot.sample.web.pojo.LoggerEntity;

@Service
public class LoggerService {

	@Autowired
	private LoggerDao loggerDao;

	public List<LoggerEntity> queryLoggerInfoList() {
		List<LoggerEntity> logger = new ArrayList<LoggerEntity>();
		Iterator<LoggerEntity> loggerIterator = loggerDao.findAll().iterator();
		while (loggerIterator.hasNext()) {
			logger.add(loggerIterator.next());
		}
		return logger;
	}

	/**
	 * 
	 * 方法描述：分页 注意事项：
	 * 
	 * @param indexPage
	 * @return
	 * @Exception 异常对象
	 */
	public Page<LoggerEntity> queryLoggerInfoListByPage(int indexPage) {
		Pageable loggerPage = new PageRequest(indexPage, 10);
		Page<LoggerEntity> loggerIterator = loggerDao.findAll(loggerPage);
		return loggerIterator;
	}
}
